package com.xuecheng.learning.controller;

import com.xuecheng.commons.model.dto.LearningProgressDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.dto.RecordDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.learning.domain.CourseRecord;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.learning.service.CourseRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 选课记录前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class CourseRecordController {

    @Autowired
    private CourseRecordService  courseRecordService;

    /**
     * 获取当前课程发布的学习进度
     * @param coursePubId 课程发布id
     * @return vo
     */
    @GetMapping("/learnedRecords/myCourseRec/{coursePubId}")
    public ResponseResult myCourseRec(@PathVariable("coursePubId") Long coursePubId){
        return  courseRecordService.findByCoursePubId(coursePubId);
    }

    /**
     * 获取课程视频资源地址
     * @param coursePubId 课程发布id
     * @param mediaId 媒资id
     * @param teachplanId 课程计划id
     * @return
     */
    @GetMapping("/learnedRecords/resource-url")
    public ResponseResult findPlayUrl(Long coursePubId,Long mediaId, Long teachplanId){
        return courseRecordService.findPlayUrl(coursePubId,mediaId,teachplanId);
    }

    /**
     * 生成/更新课程发布的学习进度
     * @param dto LearningProgressDto
     * @return null
     */
    @PostMapping("/learnedRecords/progress")
    public ResponseResult progress(@RequestBody LearningProgressDto dto){
        return courseRecordService.progress(dto);
    }

    /**
     * 分页查询个人选课记录
     * @param pageRequest 分页对象
     * @return vo
     */
    @PostMapping("/learnedRecords/list")
    public ResponseResult<CourseRecord> myCourses(PageRequest pageRequest){
        return courseRecordService.myCourses(pageRequest);
    }
}
